/**
 * 
 */
package misc;

import java.awt.Font;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

import javax.swing.JTextField;

/**
 * @author Kevin Hanson
 * 
 */
public class TextFieldFocusListener implements FocusListener {
	private JTextField textField = null;
	public final static String defaultString = "#Input string";

	public TextFieldFocusListener(JTextField tf) {
		textField = tf;
		textField.setText(defaultString);
		textField.setFont(new Font(null, Font.ITALIC, 12));
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
	 */
	@Override
	public void focusGained(FocusEvent arg0) {
		textField.selectAll();
		textField.setFont(new Font(null, Font.PLAIN, 12));
		textField.setText("");
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent)
	 */
	@Override
	public void focusLost(FocusEvent arg0) {
		if (textField.getText().isEmpty()) {
			textField.setText("#Input string");
			textField.setFont(new Font(null, Font.ITALIC, 12));
		}
	}
}
